package com.xhh.nphm.web.controller.system;

import com.xhh.nphm.common.core.controller.BaseController;
import com.xhh.nphm.common.core.domain.AjaxResult;
import com.xhh.nphm.common.core.domain.entity.SysUser;
import com.xhh.nphm.common.utils.StringUtils;
import com.xhh.nphm.system.domain.DeptDeadLine;
import com.xhh.nphm.system.service.IDeptDeadLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/system/deptdeadline")
public class DeptDeadLineController extends BaseController {
    @Autowired
    private IDeptDeadLineService deptDeadLineService;

    @PostMapping("/save")
    public AjaxResult save(DeptDeadLine deptDeadLine) {
        SysUser user = getSysUser();
        deptDeadLine.setDeptNo(user.getDeptId().toString());
        boolean flag = true;
        if(deptDeadLine.getDelayDays() != null) {

            flag = deptDeadLineService.saveOrUpdate(deptDeadLine);
        }
        return toAjax(flag);
    }

    @RequestMapping("/findBydeptNo")
    public DeptDeadLine findBydeptNo(String deptNo) {
        return deptDeadLineService.findBydeptNo(deptNo);
    }

    @RequestMapping("/config")
    public ModelAndView config(ModelMap modelMap) {
        DeptDeadLine deptDeadLine = deptDeadLineService.findBydeptNo(getSysUser().getDeptId().toString());
        modelMap.put("deptDeadLine", deptDeadLine);
        return new ModelAndView("/system/deptDeadLine/config");
    }
}
